package com.ruoyi.safe.controller.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.CommonCooperatorBadness;
import com.ruoyi.safe.service.ICommonCooperatorBadnessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合作单位-不良记录Controller
 * 
 * @author ruoyi
 * @date 2023-11-08
 */
@RestController
@RequestMapping("/common/badness")
public class CommonCooperatorBadnessController extends BaseController
{
    @Autowired
    private ICommonCooperatorBadnessService commonCooperatorBadnessService;

    /**
     * 查询合作单位-不良记录列表
     */
    @PreAuthorize("@ss.hasPermi('common:badness:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonCooperatorBadness commonCooperatorBadness)
    {
        startPage();
        List<CommonCooperatorBadness> list = commonCooperatorBadnessService.selectCommonCooperatorBadnessList(commonCooperatorBadness);
        return getDataTable(list);
    }

    /**
     * 导出合作单位-不良记录列表
     */
    @PreAuthorize("@ss.hasPermi('common:badness:export')")
    @Log(title = "合作单位-不良记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommonCooperatorBadness commonCooperatorBadness)
    {
        List<CommonCooperatorBadness> list = commonCooperatorBadnessService.selectCommonCooperatorBadnessList(commonCooperatorBadness);
        ExcelUtil<CommonCooperatorBadness> util = new ExcelUtil<CommonCooperatorBadness>(CommonCooperatorBadness.class);
        util.exportExcel(response, list, "合作单位-不良记录数据");
    }

    /**
     * 获取合作单位-不良记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('common:badness:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commonCooperatorBadnessService.selectCommonCooperatorBadnessById(id));
    }

    /**
     * 新增合作单位-不良记录
     */
    @PreAuthorize("@ss.hasPermi('common:badness:add')")
    @Log(title = "合作单位-不良记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonCooperatorBadness commonCooperatorBadness)
    {
        return toAjax(commonCooperatorBadnessService.insertCommonCooperatorBadness(commonCooperatorBadness));
    }

    /**
     * 修改合作单位-不良记录
     */
    @PreAuthorize("@ss.hasPermi('common:badness:edit')")
    @Log(title = "合作单位-不良记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonCooperatorBadness commonCooperatorBadness)
    {
        return toAjax(commonCooperatorBadnessService.updateCommonCooperatorBadness(commonCooperatorBadness));
    }

    /**
     * 删除合作单位-不良记录
     */
    @PreAuthorize("@ss.hasPermi('common:badness:remove')")
    @Log(title = "合作单位-不良记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commonCooperatorBadnessService.deleteCommonCooperatorBadnessByIds(ids));
    }
}
